package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.DishMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理")
public class DishController {
    @Autowired
    private DishService dishService;
    @Autowired
    private DishMapper dishMapper;

    /**
     * add dish
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result<Object> addDish(@RequestBody DishDTO dishDTO) {
        log.info("add dish:{}", dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * dish page
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
        log.info("page dish:{}", dishPageQueryDTO);
        return Result.success(dishService.pageQuery(dishPageQueryDTO));
    }

    /**
     * delete dish multiply
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除")
    public Result<Object> Delete(@RequestParam List<Long> ids){
        log.info("delete dish:{}", ids);
        dishService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * get dish by id
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("id查询菜品")
    public Result<DishVO> getById(@PathVariable Long id){
        log.info("get dish:{}", id);
        return Result.success(dishService.getById(id));
    }

    /**
     * update dish
     * @param dishDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品")
    public Result<Object> updateDish(@RequestBody DishDTO dishDTO){
        log.info("update dish:{}", dishDTO);
        dishService.updateDish(dishDTO);
        return Result.success();
    }

    /**
     * get dishs by categoryid
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("通过分类id查询菜品")
    public Result<List<Dish>> list(Long categoryId){
        log.info("list dish:{}", categoryId);
        return Result.success(dishService.list(categoryId));
    }
}
